/*
This do file regress city specific stringency coefficients on city characteristics
Created by Junfu Zhang 
Last updated: 2/28/2016
*/


set more off

use citylevelupdated_2.dta, clear

count if year == 2005
keep if year == 2005

gsort city_pinyin year -popinnercity
drop if city_pinyin == city_pinyin[_n-1] & year == year[_n-1]

gen population=popinnercity 

gen lncitysize=log(population)
gen lncitysize2=(lncitysize)^2
gen lnrevenue=log(fiscalrevenue*10/population)
gen lnbeds=log(hospitalbeds*10/population)
gen lnbooks=log(library*10/population)
gen lnbus=log(bus*10/population)
gen lnroad=log(roadpercapita)
gen lngreen=log(greenland*10/population)


 
//Merge with city specific coefficients for residential land
sort city_pinyin
merge 1:1 city_pinyin using R_CityCoefficients
tab _merge
rename _merge residential_merge

//Merge with city specific coefficients for commercial land
sort city_pinyin
merge 1:1 city_pinyin using C_CityCoefficients
tab _merge
rename _merge commercial_merge

count if residential_merge == 3 | commercial_merge == 3

//Merge with city specific coefficients for residential land from cluster sample
sort city_pinyin
merge 1:1 city_pinyin using R_CityCoefficients_2
tab _merge
rename _merge residential_merge_2

//Merge with city specific coefficients for commercial land from cluster sample
sort city_pinyin
merge 1:1 city_pinyin using C_CityCoefficients_2
tab _merge
rename _merge commercial_merge_2

keep if residential_merge == 3 | commercial_merge == 3 | residential_merge_2 == 3 | commercial_merge_2 == 3
drop residential_merge commercial_merge residential_merge_2 commercial_merge_2



//merge with data collected by Shihe for REStat RR
merge 1:1 city using CityCharacteristicsForRESTatRR.dta
keep if _merge == 3
drop _merge


/****************************************************
***              Block 1                         ****
*** Residential land, city specific coefficients ****
*****************************************************/

regr R_CityCoeff lncitysize lnrevenue lnbus lnroad

//num_wenwu: number of historical sites
regr R_CityCoeff num_wenwu 
regr R_CityCoeff num_wenwu lncitysize lnrevenue lnbus lnroad    // *** Table 3, col (1) ***

//historical_round: when was designinated as historical city or never was
regr R_CityCoeff historical_round
regr R_CityCoeff historical_round lncitysize lnrevenue lnbus lnroad 
xi: regr R_CityCoeff i.historical_round
xi: regr R_CityCoeff i.historical_round lncitysize lnrevenue lnbus lnroad

//tourist_round: when was designinated as tourist city or never was
regr R_CityCoeff tourist_round
regr R_CityCoeff tourist_round lncitysize lnrevenue lnbus lnroad 
xi: regr R_CityCoeff i.tourist_round
xi: regr R_CityCoeff i.tourist_round lncitysize lnrevenue lnbus lnroad


ge tourist_round2 = 0
replace tourist_round2 = 1 if tourist_round > 5 //Designated as tourist city after 2004
list city touristcity_date if tourist_round2 == 1 & R_CityCoeff != .
list city touristcity_date if tourist_round2 == 1 & C_CityCoeff != .
//tourist_round2: when was designinated as tourist city, respecified
regr R_CityCoeff tourist_round2
regr R_CityCoeff tourist_round2 lncitysize lnrevenue lnbus lnroad   // *** Table 3, col (1) ***


//OverallScore: quality of life score
regr R_CityCoeff OverallScore
regr R_CityCoeff OverallScore lncitysize lnrevenue lnbus lnroad 

//January/July temperature
regr R_CityCoeff Jan_Temp_30YearAvg
regr R_CityCoeff Jan_Temp_30YearAvg lncitysize lnrevenue lnbus lnroad
regr R_CityCoeff July_Temp_30YearAvg
regr R_CityCoeff July_Temp_30YearAvg lncitysize lnrevenue lnbus lnroad
regr R_CityCoeff Annual_Precip_30YearAvg
regr R_CityCoeff Annual_Precip_30YearAvg lncitysize lnrevenue lnbus lnroad

rename a1078 SecondSectorShare //in local GDP
rename a1080 ThirdSectorShare //in local GDP
//City industry structure
regr R_CityCoeff SecondSectorShare
regr R_CityCoeff SecondSectorShare lncitysize lnrevenue lnbus lnroad   // *** Table 3, col (1) ***
regr R_CityCoeff ThirdSectorShare
regr R_CityCoeff ThirdSectorShare lncitysize lnrevenue lnbus lnroad

//City prototype based on Urban Studies article
xi: regr R_CityCoeff i.prototype
xi: regr R_CityCoeff i.prototype lncitysize lnrevenue lnbus lnroad



/****************************************************
***              Block 2                         ****
*** Commercial land, city specific coefficients  ****
*****************************************************/

regr C_CityCoeff lncitysize lnrevenue lnbus lnroad

//num_wenwu: number of historical sites
regr C_CityCoeff num_wenwu 
regr C_CityCoeff num_wenwu lncitysize lnrevenue lnbus lnroad   // *** Table 3, col (3) ***

//historical_round: when was designinated as historical city or never was
regr C_CityCoeff historical_round
regr C_CityCoeff historical_round lncitysize lnrevenue lnbus lnroad 
xi: regr C_CityCoeff i.historical_round
xi: regr C_CityCoeff i.historical_round lncitysize lnrevenue lnbus lnroad

//tourist_round: when was designinated as tourist city or never was
regr C_CityCoeff tourist_round
regr C_CityCoeff tourist_round lncitysize lnrevenue lnbus lnroad 
xi: regr C_CityCoeff i.tourist_round
xi: regr C_CityCoeff i.tourist_round lncitysize lnrevenue lnbus lnroad

//tourist_round2: when was designinated as tourist city, respecified
regr C_CityCoeff tourist_round2
regr C_CityCoeff tourist_round2 lncitysize lnrevenue lnbus lnroad   // *** Table 3, col (3) ***


//OverallScore: quality of life score
regr C_CityCoeff OverallScore
regr C_CityCoeff OverallScore lncitysize lnrevenue lnbus lnroad 

//January/July temperature
regr C_CityCoeff Jan_Temp_30YearAvg
regr C_CityCoeff Jan_Temp_30YearAvg lncitysize lnrevenue lnbus lnroad
regr C_CityCoeff July_Temp_30YearAvg
regr C_CityCoeff July_Temp_30YearAvg lncitysize lnrevenue lnbus lnroad
regr C_CityCoeff Annual_Precip_30YearAvg
regr C_CityCoeff Annual_Precip_30YearAvg lncitysize lnrevenue lnbus lnroad

//City industry structure
regr C_CityCoeff SecondSectorShare
regr C_CityCoeff SecondSectorShare lncitysize lnrevenue lnbus lnroad   // *** Table 3, col (3) ***
regr C_CityCoeff ThirdSectorShare
regr C_CityCoeff ThirdSectorShare lncitysize lnrevenue lnbus lnroad

//City prototype based on Urban Studies article
xi: regr C_CityCoeff i.prototype
xi: regr C_CityCoeff i.prototype lncitysize lnrevenue lnbus lnroad



/****************************************************
***              Block 3                         ****
*** Residential land, city specific coefficients ****
***		from cluster sample                      ****
*****************************************************/

regr R_CityCoeff2 lncitysize lnrevenue lnbus lnroad

//num_wenwu: number of historical sites
regr R_CityCoeff2 num_wenwu 
regr R_CityCoeff2 num_wenwu lncitysize lnrevenue lnbus lnroad   // *** Table 3, col (2) ***

//historical_round: when was designinated as historical city or never was
regr R_CityCoeff2 historical_round
regr R_CityCoeff2 historical_round lncitysize lnrevenue lnbus lnroad 
xi: regr R_CityCoeff2 i.historical_round
xi: regr R_CityCoeff2 i.historical_round lncitysize lnrevenue lnbus lnroad

//tourist_round: when was designinated as tourist city or never was
regr R_CityCoeff2 tourist_round
regr R_CityCoeff2 tourist_round lncitysize lnrevenue lnbus lnroad 
xi: regr R_CityCoeff2 i.tourist_round
xi: regr R_CityCoeff2 i.tourist_round lncitysize lnrevenue lnbus lnroad

//tourist_round2: when was designinated as tourist city, respecified
regr R_CityCoeff2 tourist_round2
regr R_CityCoeff2 tourist_round2 lncitysize lnrevenue lnbus lnroad    // *** Table 3, col (2) ***


//OverallScore: quality of life score
regr R_CityCoeff2 OverallScore
regr R_CityCoeff2 OverallScore lncitysize lnrevenue lnbus lnroad 

//January/July temperature
regr R_CityCoeff2 Jan_Temp_30YearAvg
regr R_CityCoeff2 Jan_Temp_30YearAvg lncitysize lnrevenue lnbus lnroad
regr R_CityCoeff2 July_Temp_30YearAvg
regr R_CityCoeff2 July_Temp_30YearAvg lncitysize lnrevenue lnbus lnroad
regr R_CityCoeff2 Annual_Precip_30YearAvg
regr R_CityCoeff2 Annual_Precip_30YearAvg lncitysize lnrevenue lnbus lnroad

//City industry structure
regr R_CityCoeff2 SecondSectorShare
regr R_CityCoeff2 SecondSectorShare lncitysize lnrevenue lnbus lnroad   // *** Table 3, col (2) ***
regr R_CityCoeff2 ThirdSectorShare
regr R_CityCoeff2 ThirdSectorShare lncitysize lnrevenue lnbus lnroad

//City prototype based on Urban Studies article
xi: regr R_CityCoeff2 i.prototype
xi: regr R_CityCoeff2 i.prototype lncitysize lnrevenue lnbus lnroad



/****************************************************
***              Block 4                         ****
*** Commercial land, city specific coefficients  ****
***		from cluster sample                      ****
*****************************************************/

regr C_CityCoeff2 lncitysize lnrevenue lnbus lnroad

//num_wenwu: number of historical sites
regr C_CityCoeff2 num_wenwu 
regr C_CityCoeff2 num_wenwu lncitysize lnrevenue lnbus lnroad    // *** Table 3, col (4) ***

//historical_round: when was designinated as historical city or never was
regr C_CityCoeff2 historical_round
regr C_CityCoeff2 historical_round lncitysize lnrevenue lnbus lnroad 
xi: regr C_CityCoeff2 i.historical_round
xi: regr C_CityCoeff2 i.historical_round lncitysize lnrevenue lnbus lnroad

//tourist_round: when was designinated as tourist city or never was
regr C_CityCoeff2 tourist_round
regr C_CityCoeff2 tourist_round lncitysize lnrevenue lnbus lnroad 
xi: regr C_CityCoeff2 i.tourist_round
xi: regr C_CityCoeff2 i.tourist_round lncitysize lnrevenue lnbus lnroad

//tourist_round2: when was designinated as tourist city, respecified
regr C_CityCoeff2 tourist_round2
regr C_CityCoeff2 tourist_round2 lncitysize lnrevenue lnbus lnroad     // *** Table 3, col (4) ***
list city touristcity_date if tourist_round2 == 1 & C_CityCoeff2 != . //which cities drive the results


//OverallScore: quality of life score
regr C_CityCoeff2 OverallScore
regr C_CityCoeff2 OverallScore lncitysize lnrevenue lnbus lnroad 

//January/July temperature
regr C_CityCoeff2 Jan_Temp_30YearAvg
regr C_CityCoeff2 Jan_Temp_30YearAvg lncitysize lnrevenue lnbus lnroad
regr C_CityCoeff2 July_Temp_30YearAvg
regr C_CityCoeff2 July_Temp_30YearAvg lncitysize lnrevenue lnbus lnroad
regr C_CityCoeff2 Annual_Precip_30YearAvg
regr C_CityCoeff2 Annual_Precip_30YearAvg lncitysize lnrevenue lnbus lnroad

//City industry structure
regr C_CityCoeff2 SecondSectorShare
regr C_CityCoeff2 SecondSectorShare lncitysize lnrevenue lnbus lnroad   // *** Table 3, col (4) ***
regr C_CityCoeff2 ThirdSectorShare
regr C_CityCoeff2 ThirdSectorShare lncitysize lnrevenue lnbus lnroad

//City prototype based on Urban Studies article
xi: regr C_CityCoeff2 i.prototype
xi: regr C_CityCoeff2 i.prototype lncitysize lnrevenue lnbus lnroad


clear

